class Solution:
    def longestConsecutive_(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        set = {}
        for i in nums:
            if i in set:
                continue
            set[i] = True
        max_ = 0
        for i in nums:
            if i-1 in set:
                continue
            offset = 1
            while i+offset in set:
                offset += 1
            max_ = max(max_, offset)
        return max_


    def longestConsecutive(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        list = []
        map = {}
        res = 0
        for i in nums:
            if i in list:
                continue
            list.append(i)
            now = 1
            left = i
            right = i
            if i-1 in list:
                left = map.get(i-1)
                now += i-left
            if i+1 in list:
                right = map.get(i+1)
                now += right-i
            res = max(res, now)
            map[left] = right
            map[right] = left
        return res

